//
//  Copyright (c) 2018. Uber Technologies
//
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//
//  http://www.apache.org/licenses/LICENSE-2.0
//
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

import Concurrency
import SourceParsingFramework
import XCTest
@testable import NeedleFramework

class HashUtilsTests: XCTestCase {

    func test_generate_md5_hash_for_a_string() {
        let expectedHashString = "5d41402abc4b2a76b9719d911017c592" // Generated by executing "md5 -s "hello"
        XCTAssertEqual(expectedHashString, MD5(string: "hello"))
    }

    func test_generate_hash_of_hash_entries() {
        let hashEntries : Set<HashEntry> =  [ HashEntry(name: "bbb", hash: "second-string-hash"),
                                              HashEntry(name: "aaa", hash: "first-string-hash"),
                                              HashEntry(name: "ccc", hash: "third-string-hash")
                                            ]
        let hash  = generateCumulativeHash(hashEntries: hashEntries)
        let generatedString = "aaa:first-string-hash\nbbb:second-string-hash\nccc:third-string-hash\n"
        XCTAssertEqual(MD5(string: generatedString), hash)
    }
}
